const topExtraPx = 40;
export const rssConfigData = (data = {}) => {
  console.log(data);
  let {
    profile = "",
    // username,
    cover = "",
    code = "",
    bgImage = "",
    goodsName = "",
    price = "",
    shareImg,
    nicknameColor,
    profilePosition = "{}",
    profileStyle,
    qrCodePosition = "{}",
    qrCodeStyle,
    showGoods,
    showPrice,
    styleType,
    username = "",
  } = data;
  const profileXy = JSON.parse(profilePosition);
  const qrCodeXy = JSON.parse(qrCodePosition);
  const computedImage = (num) => {
    return num * 1.75 * 2;
  };
  const computedFontImage = (size) => {
    let num = size - 93 + 20;
    return computedImage(num > 0 ? num : 0);
  };
  const computedFontPadding = (str, size) => {
    if (str.length < 4) {
      return computedImage(size + 8);
    } else {
      return computedImage(size);
    }
  };
  const dw = 54;
  if (!styleType) {
    const qrCode = {
      width: computedImage(65),
      height: computedImage(65),
      x: computedImage(qrCodeXy.x || 142),
      y: computedImage(qrCodeXy.y || 306),
      url: code,
      zIndex: 100,
      show: qrCodeStyle === "1",
    };
    const profilePos1 = {
      width: computedImage(47),
      height: computedImage(47),
      x: computedImage(profileXy.x || 87),
      y: computedImage(profileXy.y || 19),
      url: profile,
      zIndex: 100,
      show: profileStyle === "1",
      borderRadius: 170,
    };
    const profilePos2 = {
      width: computedImage(47),
      height: computedImage(47),
      x: computedImage(profileXy.x || 12),
      y: computedImage(profileXy.y + 20 || 6 + 20),
      url: profile,
      zIndex: 100,
      borderRadius: 170,
      show: profileStyle === "2",
    };
    const profilefont1 = {
      x: computedFontImage(profileXy.x || 87),
      y: computedImage(profileXy.y + dw || 19 + dw),
      width: computedImage(187),
      height: computedImage(14),
      text: {
        lineHeight: 1,
        text: username,
        fontSize: computedImage(13),
        color: nicknameColor,
        fontWeight: "bold",
        lineNum: 1,
        zIndex: 999,
        baseLine: "middle",
        textAlign: "center",
      },
      show: profileStyle === "1",
    };
    const profilefont2 = {
      x: computedImage(profileXy.x ? profileXy.x + 52 : 20 + 52),
      y: computedImage(profileXy.y ? profileXy.y + 42 : 6 + 42),
      text: username,
      fontSize: computedImage(13),
      color: nicknameColor,
      lineNum: 1,
      zIndex: 999,
      baseLine: "middle",
      show: profileStyle === "2",
    };
    return {
      width: 750,
      height: 1334,
      blocks: [
        {
          show: showGoods === "1",
          backgroundColor: "#ffffff",
          y: computedImage(205),
          height: computedImage(67),
          width: computedImage(192),
          x: computedImage(11),
          zIndex: 10,
          borderRadius: 24,
        },
        {
          y: computedImage(202),
          x: computedImage(23),
          text: {
            text: goodsName,
            width: computedImage(163),
            height: computedImage(29),
            fontSize: computedImage(11),
            lineHeight: computedImage(15),
            fontWeight: "bold",
            lineNum: 2,
            zIndex: 999,
            baseLine: "middle",
          },
          show: showGoods === "1",
          width: computedImage(173),
          height: computedImage(39),
          lineNum: 1,
          zIndex: 11,
        },
        profilefont1,
      ].filter((item) => {
        const { show = true } = item;
        return show;
      }),
      texts: [
        profilefont2,
        {
          y: computedImage(253),
          x: computedImage(23),
          fontSize: computedImage(14),
          text: price ? "¥ " + price : "免费",
          lineNum: 1,
          zIndex: 999,
          fontWeight: "bold",
          color: "#ff8533",
          baseLine: "middle",
          show: showPrice === "1" && showGoods === "1",
        },
      ].filter((item) => {
        const { show = true } = item;
        return show;
      }),
      images: [
        {
          url: bgImage, // 背景
          width: 750,
          height: 1367,
          x: 0,
          y: 0,
        },
        {
          show: showGoods === "1",
          url: cover, // 背景
          y: computedImage(106),
          height: computedImage(108),
          width: computedImage(192),
          x: computedImage(11),
          borderRadius: 24,
        },
        profilePos1,
        profilePos2,
        qrCode,
      ].filter((item) => {
        const { show = true } = item;
        return show;
      }),
    };
  } else {
    const qrCode = {
      width: computedImage(65),
      height: computedImage(65),
      x: computedImage(qrCodeXy.x || 142),
      y: computedImage(qrCodeXy.y || 306),
      url: code,
      zIndex: 100,
      show: qrCodeStyle === "1",
    };
    const profilePos1 = {
      width: computedImage(47),
      height: computedImage(47),
      x: computedImage(profileXy.x || 87),
      y: computedImage(profileXy.y || 19),
      url: profile,
      zIndex: 100,
      show: profileStyle === "1",
      borderRadius: 170,
    };
    const profilePos2 = {
      width: computedImage(47),
      height: computedImage(47),
      x: computedImage(profileXy.x || 12),
      y: computedImage(profileXy.y + 20 || 6 + 20),
      url: profile,
      zIndex: 100,
      borderRadius: 170,
      show: profileStyle === "2",
    };
    const profilefont1 = {
      x: computedFontImage(profileXy.x || 87),
      y: computedImage(profileXy.y + dw || 19 + dw),
      width: computedImage(187),
      height: computedImage(14),
      text: {
        text: username,
        fontSize: computedImage(13),
        color: nicknameColor,
        lineHeight: computedImage(18),
        fontWeight: "bold",
        lineNum: 1,
        zIndex: 999,
        baseLine: "middle",
        textAlign: "center",
      },
      show: profileStyle === "1",
    };
    const profilefont2 = {
      x: computedImage(profileXy.x ? profileXy.x + 52 : 20 + 52),
      y: computedImage(profileXy.y ? profileXy.y + 42 : 6 + 42),
      text: username,
      fontSize: computedImage(13),
      color: nicknameColor,
      lineNum: 1,
      zIndex: 999,
      baseLine: "middle",
      show: profileStyle === "2",
    };
    return {
      width: 750,
      height: 1334,
      blocks: [
        {
          show: showGoods === "1",
          backgroundColor: "#ffffff",
          y: computedImage(136),
          height: computedImage(147),
          width: computedImage(192),
          x: computedImage(11),
          borderRadius: 24,
        },
        {
          y: computedImage(202),
          x: computedImage(23),
          text: {
            text: goodsName,
            width: computedImage(163),
            height: computedImage(29),
            fontSize: computedImage(11),
            lineHeight: computedImage(15),
            fontWeight: "bold",
            lineNum: 2,
            zIndex: 999,
            baseLine: "middle",
          },
          show: showGoods === "1",
          width: computedImage(173),
          height: computedImage(39),
          lineNum: 1,
          zIndex: 11,
        },
        profilefont1,
      ].filter((item) => {
        const { show = true } = item;
        return show;
      }),
      texts: [
        profilefont2,
        {
          y: computedImage(253),
          x: computedImage(23),
          fontSize: computedImage(11),
          text: price ? "¥ " + price : "免费",
          lineNum: 1,
          zIndex: 999,
          fontWeight: "bold",
          color: "#ff8533",
          baseLine: "middle",
          show: showPrice === "1" && showGoods === "1",
        },
      ].filter((item) => {
        const { show = true } = item;
        return show;
      }),
      images: [
        {
          url: bgImage, // 背景
          width: 750,
          height: 1367,
          x: 0,
          y: 0,
        },
        {
          show: showGoods === "1",
          url: cover, // 背景
          y: computedImage(113),
          height: computedImage(97),
          width: computedImage(173),
          x: computedImage(21),
          zIndex: 10,
          borderRadius: 24,
        },
        profilePos1,
        profilePos2,
        qrCode,
      ].filter((item) => {
        const { show = true } = item;
        return show;
      }),
    };
  }
};
